Repository navigation
fix(runtime): keep a constructed instance's recorded class - #2132
Conversation
CallJSMethodNative replaced the class recorded for a JS-extended instance, on the Java constructor's call into JS, with env.GetObjectClass(obj): a JNI local ref, freed when the call returned, to com.tns.Runtime's class (obj is the receiver of the native method, not the instance). The error a failed Java object lookup reports names that class, so it named com.tns.Runtime or read a dead reference. Registration already records the instance's class as a global ref.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Description
Runtime::CallJSMethodNative, on the Java constructor's call into JS (isConstructor), replaced the class recorded for the instance withenv.GetObjectClass(obj).objis the receiver of the native method, thecom.tns.Runtimeobject, not the instance, and the result is a JNI local reference that is freed when the native call returns. So for a JS-extended instance whose constructor calls into JS, the recorded class became a dead local ref tocom.tns.Runtime's class.On
mainonly one place reads it: the "Failed to get Java object by ID. id=…, class=…" error, which therefore namedcom.tns.Runtimeor read a freed reference. Registration (CallbackHandlers::RegisterInstance,Runtime::CreateJSInstanceNative) already records the instance's real class as a cached global ref, so the overwrite is simply removed. Found while porting the canary wrapper lifetime mode (#2127), which keeps the recorded class.Testing
Full suite on an arm64 API 36.1 emulator: 1773 specs, 0 failures. No spec: the only observable effect on
mainis the class name in that error message, reached when a Java object lookup fails.Summary by CodeRabbit